<template>
  <div>
    <nav-bar :title="title"></nav-bar>
    <van-tabs>
      <van-tab title="律师咨询卡" >
        <div class="pub-tab">
          <img :src="img_consult_url" style="width:100%;"/>
          <h3 style="text-align:center;">扫码发放咨询卡</h3>
        </div>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
import NavBar from "@/components/NavBar"
import { show_bg_qrcode }  from '@/api/service' 
export default {
  name:"publicity",
  components: {
    NavBar
  },
  props: {},
  data() {
    return {
      title: this.$route.meta.title,
      img_consult_url: "",
      openid: localStorage.getItem("openid"),
    };
  },
  computed: {},
  methods: {
    getConsultQRCode(){
        const url = 'http://' + window.location.host + '/#/card_consult_add/?openid=' + this.openid
        console.log(url)
        const params = {
          url: url,
          code: "consult",
        }
        show_bg_qrcode(params).then(res=>{
          return 'data:image/png;base64,' + btoa( new Uint8Array(res.data).reduce((data, byte) => data + String.fromCharCode(byte), ''));
        }).then(data=>{
          this.img_consult_url = data
        })
    },
  },
  created() {
    this.getConsultQRCode()
  },

};
</script>

<style  scoped>
.van-tabs{
  margin-top:15px;
}
.pub-tab{
  padding: 10px 10px;
}
</style>